package API.MathDome;

import java.util.Random;

/**
 * ClassName:MathText003
 * Package:API.MathDome
 * Description:
 *
 * @Author:ZhangXin
 * @Create2023/1/30-19:48
 * @Version:v1.0
 */
public class MathText003 {
    //判断一个数是否是质数
    public static void main(String[] args) {
        Random r = new Random();
        int number = r.nextInt(100) + 1;
        boolean flag = isPrime(number);
        if (flag) {
            System.out.println(number + "是一个质数");
        } else {
            System.out.println(number + "不是一个质数");
        }
    }

    private static boolean isPrime(int number) {
        int count = 0;
        for (int i = 2; i < Math.sqrt(number); i++) {
            count++;
            if (number % i == 0) {
                return false;
            }
        }
        System.out.println("循环了" + count + "次");

        return true;
    }
}
